package com.goro;

import javax.ejb.EJB;

import com.joro.Magazine;
import com.joro.ejb.MagazineFacadeLocal;

public class MagazineEditBean {

	@EJB
	protected MagazineFacadeLocal magazineDao;

	private Magazine magazine;
	private int magazineId;
	private String action;
	

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;

		if (this.action != null && this.action.equals("edit")) {
			this.getMagazineData();
		}
	}

	public MagazineEditBean() {
		magazine = new Magazine();
	}

	public String getMagazineData() {
		if (this.magazineId > 0) {
			// Init the magazine member
			Magazine tempMagazine = magazineDao.getMagazineById(magazineId);
			if (tempMagazine != null) {
				this.magazine = tempMagazine;
			}
		}
		return null;
	}

	public int getMagazineId() {
		return magazineId;
	}

	public void setMagazineId(int magazineId) {
		this.magazineId = magazineId;
		this.magazine.setId(magazineId);

	}

	public Magazine getMagazine() {
		return magazine;
	}

	public void setMagazine(Magazine magazine) {
		this.magazine = magazine;
	}

	public String saveMagazine() {		
		magazineDao.saveMagazine(this.magazine);		
		return "success";
	}

	public String deleteMagazine() {
		magazineDao.deleteMagazine(magazine);		
		return "success";
	}

	public String cancel() {
		return "success";
	}
}
